package model;
import java.util.ArrayList;

public class CustomerContainer extends PersonContainer
{

private ArrayList<Customer>CustomerCollection;
private static CustomerContainer instance;

public CustomerContainer()
{super();
  CustomerCollection=new ArrayList<Customer>();
}
public static CustomerContainer getInstance()
{
 if (instance==null) 
    {
     instance= new CustomerContainer();
    }
    return instance;
}
public void addPerson(Customer customer)
{
 CustomerCollection.add(customer);
}
/*public Customer findPerson(String paddress)
{

        Person person=null;
        int index=0;
        boolean found=false;
        while(index < personCollection.size() && !found){
            person= personCollection.get(index);
            if(person.getAddress().equals(paddress))
            {found = true;
            }
            else {
                index++;
            }
        }
        if(found) {
            return personCollection.get(index);
        }
        else {
            return null;
        }
}*/
public void removePerson(String address)
{
 Person person=findPerson(address); 
        if(person !=null){
            boolean ok=personCollection.remove(person);
            if(ok){
                System.out.println("Person with the address " + address + " is now deleted");
                  } 
                }
            else{ System.out.println("There is no one living on " + address);
                }
}
 /*public boolean updateCustomer(String number, Person newCustomer){
      boolean success=false;
    
        for(int i=0; i<CustomerCollection.size();i++){ 
        if(CustomerCollection.get(i).getNumber().equals(number)){
        CustomerCollection.remove(i);
        CustomerCollection.add(newCustomer);
        success=true;
        }
       } 
      return success;
    }   */
    public boolean updatePerson(String name, Person newPerson){
      boolean success=false;
    
        for(int i=0; i<personCollection.size();i++){ 
        if(personCollection.get(i).getName().equals(name)){
        personCollection.remove(i);
        personCollection.add(newPerson);
        success=true;
        }
       } 
      return success;
    }
}